function [cost,qzero,qbase,solq]=welfarecostkalai(r,sigma,theta, A)
	size=length(r);
	u=@(x) 74.1752*x.^(0.6);
	c=@(x) 8.23249 *x.^(1.51678);
	uprime=@(x) 0.6*74.1752*x.^(0.6-1);
	cprime=@(x) 1.51678*8.23249 *x.^(1.51678-1);
	foc=@(x) (uprime(x)-cprime(x))./(theta*cprime(x)+(1-theta)*uprime(x));
	qzero=fsolve(@(x) foc(x),[0.1*ones(size,1)]);
	solq=fsolve(@(x) foc(x)-(r./(sigma*theta)),[0.1*ones(size,1)]);
	qbase=fsolve(@(x) foc(x)-(0.03./(sigma*theta)),[0.1*ones(size,1)]);
	fun= @(delta) sigma*(u(qbase*(1-delta))-c(qbase))-A*delta-sigma*(u(solq)-c(solq));
	cost=fzero(fun,0.01);
end

